package com.iseastar.guojiang.passport;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.dianxiaosan.model.Const;
import com.iseastar.guojiang.BaseFragment;
import com.iseastar.guojiang.model.ServiceTaskBean;
import com.shouhuobao.station.R;

import droid.frame.utils.lang.Str;

/**
 * Created by joker on 2017/12/25.
 * passport任务详情
 */
public class PassportTaskDetailFragment extends BaseFragment {

    private ServiceTaskBean serviceTaskBean = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (null != bundle) {
            serviceTaskBean = (ServiceTaskBean) bundle.getSerializable("item");
        }
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.passport_task_detail);
        super.findViewById();
        if (serviceTaskBean != null) {
            //同城
            if (Const.CourierTaskStatus.sameCityTask == serviceTaskBean.getTaskType()) {
                findViewById(R.id.task_weight_ll).setVisibility(View.VISIBLE);
                ((TextView) findViewById(R.id.passport_task_weight_tv)).setText(serviceTaskBean.getWeight() + "");
                findViewById(R.id.other_ll).setVisibility(View.GONE);
                findViewById(R.id.samecity_ll).setVisibility(View.VISIBLE);
                if (serviceTaskBean.getPassportType()==1){
                    ((ImageView)findViewById(R.id.samecity_take_iv)).setImageResource(R.drawable.passport_samecity_cancel_take_icon);
                    ((ImageView)findViewById(R.id.samecity_send_iv)).setImageResource(R.drawable.passport_samecity_cancel_send_icon);
                }
                ((TextView) findViewById(R.id.passport_samecity_take_build_name_tv)).setText(serviceTaskBean.getBuildName());
                ((TextView) findViewById(R.id.passport_samecity_take_address_tv)).setText(serviceTaskBean.getAddress());
                //任务取消
                if (serviceTaskBean.getPassportType()==1){
                    TextView distanceTV = (TextView) findViewById(R.id.samecity_distance_tv);
                    distanceTV.setText(Str.formatDoubleData(serviceTaskBean.getDistance1() / 1000) + "km");
                    distanceTV.setTextColor(getResources().getColor(R.color.white));
                    distanceTV.setBackgroundResource(R.drawable.courier_task_cancel_passport_type_bg);
                }else {
                    ((TextView) findViewById(R.id.samecity_distance_tv)).setText(Str.formatDoubleData(serviceTaskBean.getDistance1() / 1000) + "km");
                }
                ((TextView) findViewById(R.id.passport_samecity_send_build_name_tv)).setText(serviceTaskBean.getGiveBuildName());
                ((TextView) findViewById(R.id.passport_samecity_send_address_tv)).setText(serviceTaskBean.getGiveAddress());
            } else {
                findViewById(R.id.task_weight_ll).setVisibility(View.GONE);
                findViewById(R.id.other_ll).setVisibility(View.VISIBLE);
                findViewById(R.id.samecity_ll).setVisibility(View.GONE);
                ((TextView) findViewById(R.id.passport_build_name_tv)).setText(serviceTaskBean.getBuildName());
                ((TextView) findViewById(R.id.passport_task_address_tv)).setText(serviceTaskBean.getAddress());
            }
            ((TextView) findViewById(R.id.passport_task_money_tv)).setText(serviceTaskBean.getTaskLucre());
            ((TextView) findViewById(R.id.passport_task_distance_tv)).setText(Str.formatDoubleData(serviceTaskBean.getDistance() / 1000));
            ((TextView) findViewById(R.id.passport_task_goods_tv)).setText("物品：" + serviceTaskBean.getCategory());
            if (isEmpty(serviceTaskBean.getRemark())) {
                findViewById(R.id.remark_tv).setVisibility(View.INVISIBLE);
            } else {
                TextView remarkTV = (TextView) findViewById(R.id.remark_tv);
                remarkTV.setVisibility(View.VISIBLE);
                if (serviceTaskBean.getPassportType() == 1) {
                    remarkTV.setText("备注：" + serviceTaskBean.getRemark());
                    remarkTV.setTextColor(Color.parseColor("#B3B3B3"));
                } else {
                    remarkTV.setText("备注：" + serviceTaskBean.getRemark());
                    remarkTV.setTextColor(Color.parseColor("#ED5858"));
                }
            }
        }
    }
}
